<template>
    <div class="view">
        <div ref="header" class="nav-back">
            <span class="iconfont icon-fanhui" @click="back"></span>
            <span class="nickname">&nbsp;编辑资料</span>
            <span class="save rt" @click="save">保存</span>
        </div>
        <cube-scroll class="scroll" ref="scroll" :scroll-events="['scroll']" @scroll="scrollHandler">
            <div ref="baseData" class="self-data">
                <div class="title-box">基本资料</div>
                <div class="content-box">
                    <div class="id flex"><span>ID</span><span class="ellipsis">{{user.userNo}}</span></div>
                    <div class="nickname flex" @click="showNickNameDialog"><span>昵称</span><span class="ellipsis">{{user.nickname}}<i
                            class="iconfont icon-youbian"></i></span></div>
                    <div class="sex flex"><span>性别</span><span class="ellipsis">{{user.gender==1?'男':'女'}}</span></div>
                    <div class="age flex" @click="birthdayPicker"><span>生日</span>
                        <span class="ellipsis" v-if="user.birthday">{{user.birthday | timeStampToDay}} <i v-if="this.originalBirthday === 0" class="iconfont icon-youbian"></i></span>
                        <span class="ellipsis" v-else>未填写<i v-if="this.originalBirthday === 0" class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="height flex" @click="showCommonPicker('选择身高','height','snapHeight','HEIGHT')">
                        <span>身高</span>
                        <span class="ellipsis">{{self.snapHeight}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="education flex"
                         @click="showCommonPicker('选择学历','education','snapEducation','EDUCATION')">
                        <span>学历</span>
                        <span class="ellipsis">{{self.snapEducation}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="income flex" @click="showCommonPicker('选择月收入','income','snapIncome','INCOME')">
                        <span>月收入</span>
                        <span class="ellipsis">{{self.snapIncome}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="home flex"
                         @click="showAddressPicker('选择居住地',['provinceId','cityId','districtId'],['snapProvinceId','snapCityId','snapDistrictId'], self.snapProvinceId)">
                        <span>居住地</span>
                        <span class="ellipsis">{{self.snapCityId}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="arital-status flex"
                         @click="showCommonPicker('选择婚姻状况','maritalStatus','snapMaritalStatus','MARITAL_STATUS')">
                        <span>婚姻状况</span>
                        <span class="ellipsis">{{self.snapMaritalStatus}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="children flex" @click="showCommonPicker('选择子女情况','child','snapChild','CHILD')">
                        <span>子女情况</span>
                        <span class="ellipsis">{{self.snapChild}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="house flex"
                         @click="showCommonPicker('选择购房情况','housePurchase','snapHousePurchase','HOUSE_PURCHASE')">
                        <span>购房情况</span>
                        <span class="ellipsis">{{self.snapHousePurchase}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('选择购车情况','carPurchase','snapCarPurchase','CAR_PURCHASE')">
                        <span>购车情况</span>
                        <span class="ellipsis">{{self.snapCarPurchase}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
            <div ref="spouseFactor" class="self-base-data">
                <div class="title-box">择偶意向</div>
                <div class="content-box">
                    <div class="car flex" @click="showDiffPicker('配偶年龄','age','snapAge','AGE','','mateSelection')">
                        <span>年龄</span>
                        <span class="ellipsis">{{self.mateSelection.snapAge}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showDiffPicker('配偶身高','height','snapHeight','HEIGHT_OPTIONS','','mateSelection')">
                        <span>身高</span>
                        <span class="ellipsis">{{self.mateSelection.snapHeight}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showDiffPicker('配偶学历','education','snapEducation','EDUCATION_OPTIONS','','mateSelection')">
                        <span>学历</span>
                        <span class="ellipsis">{{self.mateSelection.snapEducation}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showDiffPicker('配偶月收入','income','snapIncome','INCOME_OPTIONS','','mateSelection')">
                        <span>月收入</span>
                        <span class="ellipsis">{{self.mateSelection.snapIncome}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showAddressPicker('选择居住地',['provinceId','cityId'],['snapProvinceId','snapCityId'], self.mateSelection.snapProvinceId,'mateSelection')">
                        <span>居住地</span>
                        <span class="ellipsis">{{self.mateSelection.snapCityId}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('婚姻情况','maritalStatus','snapMaritalStatus','MARITAL_STATUS_OPTIONS','','mateSelection')">
                        <span>婚姻情况</span>
                        <span class="ellipsis">{{self.mateSelection.snapMaritalStatus}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('购房情况','housePurchase','snapHousePurchase','HOUSE_PURCHASE_OPTIONS','','mateSelection')">
                        <span>购房情况</span>
                        <span class="ellipsis">{{self.mateSelection.snapHousePurchase}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('子女情况','child','snapChild','CHILD_OPTIONS','','mateSelection')">
                        <span>子女情况</span>
                        <span class="ellipsis">{{self.mateSelection.snapChild}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
            <div class="self-base-data" ref="selfArchives">
                <div class="title-box">小档案</div>
                <div class="content-box">
                    <div class="car flex"
                         @click="showAddressPicker('选择家乡',['hometownProvinceId','hometownCityId'],['snapHometownProvinceId','snapHometownCityId'], self.snapHometownProvinceId)">
                        <span>家乡</span>
                        <span class="ellipsis">{{self.snapHometownCityId}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showAddressPicker('选择户口所在地',['registeredResidenceProvinceId','registeredResidenceCityId'],['snapRegisteredResidenceProvinceId','snapRegisteredResidenceCityId'], self.snapRegisteredResidenceProvinceId)">
                        <span>户口</span>
                        <span class="ellipsis">{{self.snapRegisteredResidenceCityId}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('选择民族','nation','snapNation','NATION')">
                        <span>民族</span>
                        <span class="ellipsis">{{self.snapNation}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('选择属相','zodiac','snapZodiac','ZODIAC')">
                        <span>属性</span>
                        <span class="ellipsis">{{self.snapZodiac}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('选择星座','constellation','snapConstellation','CONSTELLATION')">
                        <span>星座</span>
                        <span class="ellipsis">{{self.snapConstellation}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('选择血型','bloodtype','snapBloodtype','BLOODTYPE')">
                        <span>血型</span>
                        <span class="ellipsis">{{self.snapBloodtype}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('选择血型','share','snapShare','SHARE')">
                        <span>体型</span>
                        <span class="ellipsis">{{self.snapShare}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('选择体重','weight','snapWeight','WEIGHT')">
                        <span>体重</span>
                        <span class="ellipsis">{{self.snapWeight}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('对自己的相貌作出评价','evaluation','snapEvaluation','EVALUATION','选择分数')">
                        <span>相貌自评</span>
                        <span class="ellipsis">{{self.snapEvaluation}} <i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('宗教信仰','belief','snapBelief','BELIEF')">
                        <span>宗教信仰</span>
                        <span class="ellipsis">{{self.snapBelief}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('是否吸烟','smoke','snapSmoke','SMOKE')">
                        <span>是否吸烟</span>
                        <span class="ellipsis">{{self.snapSmoke}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('是否喝酒','drink','snapDrink','DRINK')">
                        <span>是否喝酒</span>
                        <span class="ellipsis">{{self.snapDrink}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('你的生活作息','dailylife','snapDailylife','DAILYLIFE')">
                        <span>生活作息</span>
                        <span class="ellipsis">{{self.snapDailylife}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
            <div class="self-base-data" ref="selfEducation">
                <div class="title-box">教育及工作</div>
                <div class="content-box">
                    <div class="car flex" @click="showUniversityDrawer">
                        <span>毕业院校</span>
                        <span class="ellipsis">{{self.snapUniversity}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('所学专业','major','snapMajor','MAJOR')">
                        <span>所学专业</span>
                        <span class="ellipsis">{{self.snapMajor}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('职业职务','duties','snapDuties','DUTIES')">
                        <span>职业职务</span>
                        <span class="ellipsis">{{self.snapDuties}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('公司性质','companyNature','snapCompanyNature','COMPANY_NATURE')">
                        <span>公司性质</span>
                        <span class="ellipsis">{{self.snapCompanyNature}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('公司行业','companyIndustry','snapCompanyIndustry','COMPANY_INDUSTRY')">
                        <span>公司行业</span>
                        <span class="ellipsis">{{self.snapCompanyIndustry}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('工作状态','workingCondition','snapWorkingCondition','WORKING_CONDITION')">
                        <span>工作状态</span>
                        <span class="ellipsis">{{self.snapWorkingCondition}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showLanguageDialog">
                        <span>掌握语言</span>
                        <span class="ellipsis">{{self.snapMasterLanguage}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
            <div class="self-base-data" ref="selfFamily">
                <div class="title-box">家庭情况</div>
                <div class="content-box">
                    <div class="car flex"
                         @click="showCommonPicker('家中排行','familyRanking','snapFamilyRanking','FAMILY_RANKING')">
                        <span>家中排行</span>
                        <span class="ellipsis">{{self.snapFamilyRanking}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('父母情况','parentSituation','snapParentSituation','PARENT_SITUATION')">
                        <span>父母情况</span>
                        <span class="ellipsis">{{self.snapParentSituation}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('父亲工作','fatherWork','snapFatherWork','FATHER_WORK')">
                        <span>父亲工作</span>
                        <span class="ellipsis">{{self.snapFatherWork}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex" @click="showCommonPicker('工作状态','motherWork','snapMotherWork','MOTHER_WORK')">
                        <span>母亲工作</span>
                        <span class="ellipsis">{{self.snapMotherWork}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('工作状态','parentEconomy','snapParentEconomy','PARENT_ECONOMY')">
                        <span>父母经济</span>
                        <span class="ellipsis">{{self.snapParentEconomy}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('父母医保','parentalInsurance','snapParentalInsurance','PARENTAL_INSURANCE')">
                        <span>父母医保</span>
                        <span class="ellipsis">{{self.snapParentalInsurance}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
            <div class="love-plan self-base-data" ref="lovePlan">
                <div class="title-box">爱情规划</div>
                <div class="content-box">
                    <div class="car flex"
                         @click="showCommonPicker('想何时结婚','marriageTime','snapMarriageTime','MARRIAGE_TIME')">
                        <span>想何时结婚</span>
                        <span class="ellipsis">{{self.snapMarriageTime}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('偏爱约会方式','datingStyle','snapDatingStyle','DATING_STYLE')">
                        <span>偏爱约会方式</span>
                        <span class="ellipsis">{{self.snapDatingStyle}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('需要对方看重','otherSideValues','snapOtherSideValues','OTHER_SIDE_VALUES')">
                        <span>需要对方看重</span>
                        <span class="ellipsis">{{self.snapOtherSideValues}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('期待婚礼形式','weddingForm','snapWeddingForm','WEDDING_FORM')">
                        <span>期待婚礼形式</span>
                        <span class="ellipsis">{{self.snapWeddingForm}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('愿意对方父母同住否','livingWithParents','snapLivingWithParents','LIVING_WITH_PARENTS')">
                        <span>愿意对方父母同住否</span>
                        <span class="ellipsis">{{self.snapLivingWithParents}}<i
                                class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('是否想要孩子','wantChildren','snapWantChildren','WANT_CHILDREN')">
                        <span>是否想要孩子</span>
                        <span class="ellipsis">{{self.snapWantChildren}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('厨艺情况','cookingCondition','snapCookingCondition','COOKING_CONDITION')">
                        <span>厨艺情况</span>
                        <span class="ellipsis">{{self.snapCookingCondition}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                    <div class="car flex"
                         @click="showCommonPicker('家庭分工','divisionOfLabour','snapDivisionOfLabour','DIVISION_OF_LABOUR')">
                        <span>家庭分工</span>
                        <span class="ellipsis">{{self.snapDivisionOfLabour}}<i class="iconfont icon-youbian"></i></span>
                    </div>
                </div>
            </div>
        </cube-scroll>
        <cube-drawer ref="universityDrawer" title="选择大学" :data="universityData" @change="drawerChangeHandler"
                     @select="drawerSelectHandler">
            <span slot="title">选择大学</span>
            <cube-drawer-panel v-for="(panel, index) in universityData" :key="index" :index="index" :data="panel">
                <cube-drawer-item :class="item.type === 0 ?'university-drawer-gather':'university-drawer-item'"
                                  v-for="(item, i) in panel" :index="i" :item="item" :key="i">
                    {{item.text}}
                </cube-drawer-item>
            </cube-drawer-panel>
        </cube-drawer>

    </div>
</template>

<script lang="ts">
    import {Component, Vue} from "vue-property-decorator";
    import Scene from "@/render/Scene";
    import Http from "@/service/Http";

    import {Getter, Action, State, Mutation} from "vuex-class";
    import {InterfaceUser} from "@/interface/InterfaceUser";
    import {updateUser} from "@/store/dispatches";
    import UserEntity from "@/entity/UserEntity";
    import CommonUnit from "@/unit/CommonUnit";
    import DialogConfig from "@/constant/DialogConfig";

    @Component({
        components: {}
    })
    export default class MineDataEdit extends Scene {

        @State("UserStore")
        public user!: InterfaceUser;
        private scrollType: string = "";
        private dataPicker: any = "";
        private commonPicker: any = "";
        private addressPicker: any = "";
        private currentKey: string = "";
        private currentSnap: string = "";
        private currentChilrenKey: string = "";
        private currentKeyArray: string[] = [];
        private currentSnapArray: string[] = [];
        private originalBirthday: number = 0;
        private addressJson: any[] = [];
        private universityData: any[] = [[], []];
        private universityTempData: any[] = [];
        private diffDataList: any[] = [];
        private diffPicket: any = "";
        private languageList: any[] = [];
        private multipleSelectionDialog: any = "";

        private get self(): InterfaceUser {
            return this.user;
        }

        private set self(user: InterfaceUser) {
            updateUser(user);
        }

        private showNickNameDialog() {
            (<any> this).$createDialog({
                type: "prompt",
                title: "修改昵称",
                content: "昵称长度为2～20个字。<br/>禁止包含黄色、暴力及广告内容!",
                prompt: {
                    value: this.user.nickname,
                    placeholder: this.user.nickname,
                    maxlength: 20,
                    clearable: {
                        visible: true,
                        blurHidden: true
                    }
                },
                onConfirm: (e: any, promptValue: string) => {
                    if (promptValue.length < 2 || promptValue.length > 20 || typeof (promptValue) !== "string") {
                        (<any> this).$createToast({
                            time: 2000,
                            txt: "昵称长度为2～20个字。请检查后重新修改",
                            type: "warn"
                        }).show();
                    } else {
                        this.$set(this.self, "nickname", promptValue);
                    }
                }
            }).show();
        }


        private birthdayPicker(): void {//出生日期选择
            if (this.originalBirthday === 0) {
                if (!this.dataPicker) {
                    this.dataPicker = (<any> this).$createDatePicker({
                        title: "选择出生日期",
                        subtitle: "仅可修改一次",
                        min: new Date(new Date().getFullYear() - 100, new Date().getMonth(), 1),
                        max: new Date(new Date().getFullYear() - 18, new Date().getMonth(), 1),
                        value: new Date(new Date().getFullYear() - 25, new Date().getMonth(), 1),
                        onSelect: this.selectBirthday
                    });
                }
                this.dataPicker.show();
            }
        }

        private async showDiffPicker(title: string, key: string, snap: string, type: string, subtitle: string = "", childrenKey: string = ""): Promise<any> {
            this.currentKey = key;
            this.currentSnap = snap;
            this.currentChilrenKey = childrenKey;
            const toast = (<any> this).$createToast({
                time: 0,
                txt: "载入数据中...",
                mask: true
            }).show();
            if (!this.diffPicket) {
                this.diffPicket = (<any> this).$createPicker({
                    title: "",
                    onChange: this.diffValueChange,
                    onSelect: this.diffValueSelect
                });
            }
            const result: any = await Http.get(this.api.getParameterItem, {type});
            this.diffDataList = CommonUnit.resultToPickerData(result.data);
            this.diffPicket.$updateProps({
                title: title,
                data: [this.diffDataList, this.diffDataList],
            });
            toast.hide();
            this.diffPicket.show();
        }

        private diffValueChange(col: number, selectedIndex: number): void {
            if (col === 0) {
                this.diffPicket.setData([this.diffDataList, this.diffDataList.slice(selectedIndex)], [selectedIndex, 0]);
            }
        }

        private diffValueSelect(value: any[], index: number[], text: string[]) {
            if (this.currentChilrenKey === "mateSelection") {
                this.$set(this.self["mateSelection"], this.currentKey, value.join(","));
                this.$set(this.self["mateSelection"], this.currentSnap, text[0] === text[1] ? text[0] : text.join("～"));
            }

        }

        private async showAddressPicker(title: string, key: string[], snap: string[], defaultIndex: string = "", childrenKey: string = ""): Promise<any> {
            this.currentKeyArray = key;
            this.currentSnapArray = snap;
            this.currentChilrenKey = childrenKey;

            const toast = (<any> this).$createToast({
                time: 0,
                txt: "载入地区数据",
                mask: true
            }).show();
            let result: any[] = await Http.read(this.api.addressJson);
            if (key.length !== 3) {
                for (let i in result) {
                    for (let j in result[i].children) {
                        delete result[i].children[j].children;
                    }
                }
            }
            if (childrenKey === "mateSelection") {
                const addressJson = result;
                for (let i in addressJson) {
                    addressJson[i].children.unshift({pid: addressJson[i].value, text: "不限", value: -1});
                }

            }
            this.addressJson.push(...result);
            toast.hide();
            this.addressPicker = (<any> this).$createCascadePicker({
                title: title,
                data: result,
                selectedIndex: defaultIndex.split(","),
                onSelect: this.addressSelect,
            });

            this.addressPicker.show();
        }

        private addressSelect(value: any[], index: number[], text: string[]) {
            if (this.currentChilrenKey === "mateSelection") {
                this.$set(this.self["mateSelection"], this.currentKeyArray[0], value[0]);
                this.$set(this.self["mateSelection"], this.currentKeyArray[1], value[1]);
                this.$set(this.self["mateSelection"], this.currentSnapArray[0], index.join(","));
                this.$set(this.self["mateSelection"], this.currentSnapArray[1], text.join(" "));
            } else {
                this.$set(this.self, this.currentKeyArray[0], value[0]);
                this.$set(this.self, this.currentKeyArray[1], value[1]);
                this.$set(this.self, this.currentSnapArray[0], index.join(","));
                this.$set(this.self, this.currentSnapArray[1], text.join(" "));
                if (this.currentKeyArray.length === 3) {
                    this.$set(this.self, this.currentKeyArray[2], value[2]);
                }
            }

        }

        private async showCommonPicker(title: string, key: string, snap: string, type: string, subtitle: string = "", childrenKey: string = ""): Promise<any> {
            const toast = (<any> this).$createToast({
                time: 0,
                txt: "载入选项中...",
                mask: true
            }).show();
            this.currentKey = key;
            this.currentSnap = snap;
            this.currentChilrenKey = childrenKey;
            const result = await Http.get(this.api.getParameterItem, {type});
            this.commonPicker.$updateProps({
                title: title,
                subtitle: subtitle,
                data: [CommonUnit.resultToPickerData(result.data)],
            });
            toast.hide();
            this.commonPicker.show();
        }

        private selectBirthday(value: string) {
            const birthday = Date.parse(value);
            this.$set(this.self, "birthday", birthday / 1000);
        }

        private async showUniversityDrawer(): Promise<any> {
            if (this.universityData[0].length === 0) {
                let toast = (<any> this).$createToast({
                    time: 0,
                    txt: "获取数据中...",
                    mask: true
                }).show();
                const result = await Http.get(this.api.getParameterItem, {type: "UNIVERSITY_PROVINCE"});
                this.universityTempData = result.data;
                Object.keys(this.universityTempData).forEach((key: any) => {
                    this.universityData[0].push({type: 0, text: key});
                    for (let i in this.universityTempData[key]) {
                        this.universityData[0].push({
                            value: key,
                            type: 1,
                            text: this.universityTempData[key][i].name,
                            key: key,
                            index: i,
                            children: this.universityTempData[key][i]
                        });
                    }
                });
                // (<any> this).$refs.universityDrawer.refill(0, this.universityData[0]);
                toast.hide();

            }
            (<any> this).$refs.universityDrawer.show();

        }

        private drawerChangeHandler(index: number, item: any): void {
            if (item.type !== 0) {
                const universityList: any[] = [];
                const children = item.children;
                for (let i in children.university) {
                    universityList.push({
                        type: 1,
                        text: children.university[i].name,
                        alias: children.university[i].alias,
                        value: children.university[i].alias
                    });
                }
                (<any> this).$refs.universityDrawer.refill(1, universityList);

            }

        }

        private drawerSelectHandler(selectedVal: any[], selectedIndex: any, selectedText: any): void {
            this.$set(this.self, "university", selectedVal[1]);
            this.$set(this.self, "snapUniversity", selectedText[1]);
        }


        private scrollHandler(pos: any): void {//scroll滚动事件
            //this.pullDownY = pos.y;
        }


        private back(): void {
            if (Number(this.$route.query.isNew) === 1) {
                const dialogConfig = new DialogConfig();
                (<any> this).$createDialog({
                    ...dialogConfig.getAppDownloadTipConfig(),
                    onConfirm: () => {
                        this.redirectTo({
                            name: "appDownload"
                        });
                    },
                    onCancel: () => {
                        this.navigateBack();
                    }
                }).show();
            } else {
                this.navigateBack();
            }
        }

        private selectCommonValue(value: any[], index: number[], text: string[]) {
            if (this.currentChilrenKey === "mateSelection") {
                this.$set(this.self["mateSelection"], this.currentKey, value.join(","));
                this.$set(this.self["mateSelection"], this.currentSnap, text.join(","));
            } else {
                this.$set(this.self, this.currentKey, value.join(","));
                this.$set(this.self, this.currentSnap, text.join(","));
            }

        }

        private async save(): Promise<any> {
            const userEntity = new UserEntity(this.user);
            let toast = (<any> this).$createToast({
                time: 0,
                txt: "保存中...",
                mask: true
            }).show();
            const baseInfoParameter = userEntity.getBaseInfoExcludeSex;
            const archivesParameter = userEntity.getArchives;
            const educationWorkParameter = userEntity.getEducationWork;
            const familyConditionParameter = userEntity.getFamilyCondition;
            const lovePlaningParameter = userEntity.getLovePlanning;
            const mateSelectionParameter = userEntity.getMateSelection;
            if (this.originalBirthday > 0) {
                delete baseInfoParameter.birthday;
            }
            try {
                const baseInfoResult = await Http.post(this.api.saveBaseInfo, {...baseInfoParameter}, {token: this.user.token});
                const archivesResult = await Http.post(this.api.saveArchives, {...archivesParameter}, {token: this.user.token});
                const educationWorkResult = await Http.post(this.api.saveEducationWork, {...educationWorkParameter}, {token: this.user.token});
                const familyConditionResult = await Http.post(this.api.saveFamilyCondition, {...familyConditionParameter}, {token: this.user.token});
                const lovePlaningResult = await Http.post(this.api.saveLovePlanning, {...lovePlaningParameter}, {token: this.user.token});
                const mateSelectionResult = await Http.post(this.api.saveMateSelection, {...mateSelectionParameter}, {token: this.user.token});
                if (baseInfoResult.code === 1 && archivesResult.code === 1 && educationWorkResult.code === 1 && familyConditionResult.code === 1 && lovePlaningResult.code === 1 && mateSelectionResult.code === 1) {
                    this.authentication();
                    toast = (<any> this).$createToast({
                        time: 2500,
                        txt: "保存成功，正在更新资料",
                        type: "correct",
                        mask: true,
                        onTimeout: () => {
                            if (Number(this.$route.query.isNew) === 1) {
                                const dialogConfig = new DialogConfig();
                                (<any> this).$createDialog({
                                    ...dialogConfig.getAppDownloadTipConfig(),
                                    onConfirm: () => {
                                        this.redirectTo({
                                            name: "appDownload"
                                        });
                                    },
                                    onCancel: () => {
                                        this.navigateBack();
                                    }
                                }).show();
                            } else {
                                this.navigateBack();
                            }
                        }
                    }).show();
                } else {
                    this.globalMultipleResultToast(baseInfoResult, archivesResult, educationWorkResult, familyConditionResult, lovePlaningResult, mateSelectionResult);
                }
            } catch (e) {
                toast.hide();
            }

        }

        private activated(): void {
            this.originalBirthday = this.user.birthday;
            this.$nextTick(() => {
                let type = String(this.$route.query.type);
                if (type !== "undefined") {
                    let scrollY = (this as any).$refs[type].offsetTop;
                    (this as any).$refs.scroll.scrollTo(0, -scrollY, 0);
                }
            });
        }

        private mounted(): void {
            this.originalBirthday = this.user.birthday;
            this.commonPicker = (<any> this).$createPicker({
                title: "",
                data: [],
                onSelect: this.selectCommonValue,
            });
            this.$nextTick(() => {
                let type = String(this.$route.query.type);
                if (type !== "undefined") {
                    let scrollY = (this as any).$refs[type].offsetTop;
                    (this as any).$refs.scroll.scrollTo(0, -scrollY, 0);
                }
            });
        }

        private async showLanguageDialog(): Promise<any> {
            if (this.multipleSelectionDialog === "" || this.languageList.length === 0) {
                const toast = (<any> this).$createToast({
                    time: 0,
                    txt: "载入数据中...",
                    mask: true
                }).show();
                const result = await Http.get(this.api.getParameterItem, {type: "MASTER_LANGUAGE"});
                const languageTempData = result.data;
                this.languageList = [];
                for (const language of languageTempData) {
                    this.languageList.push({label: language.name, value: language.alias});
                }
                toast.hide();
                this.multipleSelectionDialog = (<any> this).$createMultipleSelectionDialog({
                    title: "选择您所掌握的语言",
                    optionsList: this.languageList,
                    onConfirm: (e: any, checkValue: []) => {
                        let snapMasterLanguageArray = [];
                        for (let i in checkValue) {
                            for (let language of this.languageList) {
                                if (String(language.value) === String(checkValue[i])) {
                                    snapMasterLanguageArray.push(language.label);
                                }
                            }
                        }
                        this.$set(this.self, "masterLanguage", checkValue.join(","));
                        this.$set(this.self, "snapMasterLanguage", snapMasterLanguageArray.join(","));
                    }
                }).show();
            } else {
                this.multipleSelectionDialog.show();
            }

        }

    }
</script>

<style scoped lang="stylus">
    .view
        width 100vw;
        height 100vh;
        background $theme-page-common-background-color;
        overflow hidden

        .nav-back
            width 100vw;
            position fixed;
            left 0px;
            z-index: 100;
            color $theme-common-color;
            padding calc(15px + var(--safe-area-inset-top)) 10px 10px;
            background rgba(255, 255, 255, 1);
            border-bottom 1px solid $theme-line-color;

            .save
                font-size 16px;

            .nickname
                font-size 16px;
                color $theme-common-color;

        .scroll
            margin-top calc(47px + var(--safe-area-inset-top));
            position relative;
            height calc(100vh - var(--safe-area-inset-top) - var(--safe-area-inset-bottom));

        > div
            .title-box
                padding 15px;

            .content-box
                background-color #fff;

                > div
                    padding 15px;
                    border-bottom 1px solid $theme-line-color;
                    justify-content: space-between;

                    i.icon-youbian
                        color $theme-viceColor-font;
                        padding-left 6px;

        .love-plan
            margin-bottom 70px;


    >>> .cube-drawer
        z-index 101;
        height 100vh;

        .cube-drawer-title
            padding-top var(--safe-area-inset-top)
            flex 0 0 calc(50px + var(--safe-area-inset-top))

        .university-drawer-gather
            background #eee !important;
            line-height 30px;
            height 30px;
            color $theme-common-color;
            padding 0 10px;

        .university-drawer-item
            position relative;
            height auto;
            min-height 40px;
            line-height 20px;
            display flex;
            align-items center;
            padding 10px 15px;

        .cube-drawer-item
            background #fff;
</style>
